<h1>Listing borrowings</h1>

<table width="100%">
  <tr>
  <th>User</th>
  <th>Title</th>
  <% for column in Borrowing.content_columns -%>
    <% unless ['idx'].include?(column.name) -%>
      <th><%= column.human_name -%></th>
    <% end -%> 
  <% end -%>
    <th>State</th>
    <th colspan='4'>Action</th>
  </tr>

<% for borrowing in @borrowings -%>
  <tr>
  <td><%= link_to %Q{#{borrowing.user.surname + ' ' + borrowing.user.first_name}}, {:action => 'list', :user_id => borrowing.user.id} %></td>
  <td><%= link_to %Q{#{borrowing.book.title}}, {:action => 'list', :book_id => borrowing.book.id} %></td>
  <% for column in Borrowing.content_columns -%>
    <% unless ['state','idx'].include?(column.name) -%>
       <td><%=h borrowing.send(column.name) -%></td>
    <% end -%>
  <% end -%>
    <td><%= link_to %Q{#{format_state(borrowing.state)}}, {:action => 'list', :state => borrowing.state} %></td>
    <td><%= link_to('Return', :action => 'showreturn', :id => borrowing) if return?(borrowing) -%></td>
    <td><%= link_to 'Show', :action => 'show', :id => borrowing -%></td>
    <td><%= link_to('Edit', :action => 'edit', :id => borrowing) if edit?(borrowing) -%></td>
    <td><%= link_to 'Destroy', {:action => 'destroy', :id => borrowing} , :confirm => 'Are you sure?', :method => :post if return?(borrowing) -%></td>
   </tr>
<% end -%>
</table>

<div class='prevnext_links'>
  <%= link_to 'Previous page', { :page => @borrowing_pages.current.previous } if @borrowing_pages.current.previous -%>
  <%= link_to 'Next page', { :page => @borrowing_pages.current.next } if @borrowing_pages.current.next -%>
</div>

<%= link_to 'New borrowing', :action => 'new' -%>

